package db

import (
	logger "github.com/sirupsen/logrus"
	"github.com/spf13/cobra"
)

var configFilePath = ""
var MigrateCmd = &cobra.Command{
	Use:   "replace",
	Short: "rmb",
	Long:  "replace utf8mb4",
	Run: func(c *cobra.Command, args []string) {
		configFile, err := Load(configFilePath)
		if err != nil {
			logger.Fatalf("config is error,exit %s", err)
		}
		dbConnect := OpenDb(configFile)
		dbConnect.ReplaceAllService()
	},
}

var BackCmd = &cobra.Command{
	Use:   "back",
	Short: "back",
	Long:  "back utf8",
	Run: func(c *cobra.Command, args []string) {
		configFile, err := Load(configFilePath)
		if err != nil {
			logger.Fatalf("config is error,exit %s", err)
		}
		dbConnect := OpenDb(configFile)
		dbConnect.FallbackAllService()
	},
}

// init 解析命令参数
func init() {
	MigrateCmd.PersistentFlags().StringVarP(&configFilePath, "config", "c", "server.yaml", "config file path")
	BackCmd.PersistentFlags().StringVarP(&configFilePath, "config", "c", "server.yaml", "config file path")
}
